<?php
/**
 * Created by PhpStorm.
 * User: fengbob
 * Date: 2018/2/20
 * Time: 09:12
 */

namespace app\controllers;


use app\librarys\PayProController;
use app\models\EShopExt;
use yii\data\Pagination;

class EshopController extends PayProController
{
    public $enableCsrfValidation = false;
    static $mini_p = '1';


    /**
     *
     * @return string
     */
    public function actionEshop()
    {
        $request = \Yii::$app->request;

        $name = $request->get('name');

        $count = EShopExt::getEshopCount($name);
        $pagination = new Pagination([
            'totalCount' => $count
        ]);
        $items = EShopExt::getEshopList($pagination->page, $pagination->pageSize, $name);

        return $this->render('eshop',
            [
                'items' => $items,
                'name' => $name,
                'pagination' => $pagination
            ]);
    }

    public function actionEshopPartial()
    {
        $this->layout = false;
        $request = \Yii::$app->request;
        $id = $request->post('id');

        $item = EShopExt::getEshopById($id);
        return $this->render('eshop-partial',
            [
                'item' => $item
            ]
        );
    }

    public function actionEshopSaveHandler()
    {
        $request = \Yii::$app->request;
        $id = $request->post('id');
        $name = $request->post('name');

        $sort = $request->post('sort');
        $brief_introduction = $request->post('brief_introduction');
        $contact_man = $request->post('contact_man');
        $contact_phone = $request->post('contact_phone');
        $begin_datetime = $request->post('begin_datetime');
        $end_datetime = $request->post('end_datetime');
        $is_on = $request->post('is_on');
        $status = $request->post('status');
        $img_path = $request->post('img_path');
//        data.img_path = img_path;



        $result = EShopExt::saveEshop(EshopController::$mini_p,$id,$name,$img_path,$brief_introduction,'','','','',$is_on,$status,$sort,
            $contact_man,$contact_phone,$begin_datetime,$end_datetime);
        return $this->renderJson(null, $result ? 0 : 1, $result ? '操作成功' : '操作失败');
    }

    public function actionEshopDeleteHandler()
    {
        $request = \Yii::$app->request;
        $id = $request->post('id');

        $result = EShopExt::deleteEshop($id);
        return $this->renderJson(null, $result ? 0 : 1, $result ? '操作成功' : '操作失败');
    }

}